package ray.mgocc.swing;

import javax.swing.JInternalFrame;
import ray.mgocc.title.Title;
import ray.mgocc.title.Requirement;
import java.util.Collections;
import java.util.Map;
import javax.swing.JPasswordField;
import javax.swing.AbstractAction;
import javax.swing.KeyStroke;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.Action;
import java.awt.Panel;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JEditorPane;
import java.util.Comparator;

import java.awt.event.ActionEvent;

public class TitlePanel extends JInternalFrame{
    private Title title;
    private Action action;
    public TitlePanel(Title title){
        super(title.getName(),true,true,true,true);
        this.title = title;
        init();
    }
    public void init(){

        StringBuilder b = new StringBuilder();
        b.append("<p>");
        b.append(title.getName()).append(" ");
        b.append("[").append(title.percent()).append("%]\n");
        b.append("</p>");
        Collections.sort(title);
        b.append("<ul>");
        for(Requirement requirement:title){
            b.append("<li>").append(requirement.toString()).append("</li>");
        }
        b.append("</ul>");
        b.append("<ul>");
        java.util.List params = new java.util.ArrayList(title.getParam().entrySet());
        Comparator stringOrder = new Comparator(){
                public int compare(Object o1,Object o2){
                    return o1.toString().compareTo(o2.toString());
                }
            };
        Collections.sort(params,stringOrder);
        for(Object param:params){
            b.append("<li>").append(param).append("</li>");
        }
        b.append("</ul>");

        JEditorPane text = new JEditorPane();
        text.setContentType("text/html");
        text.setText(b.toString());
        text.setEditable(false);

        add(text);
    }

}

